<template>
<view :class="[config.style]">
		<!--数据列表部分-->
		<view class="list-section uni-clearfix">
			<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="0" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 数据列表 -->
				<view class="list">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="title">
							<text class="status" :class="item.useful?'green':'red'">{{item.useful_str}}</text>
						</view>
						<!-- 
						<view class="delete" v-if="item.useful == 0">
							<text class="iconfont">&#xe6bf;</text>
						</view>
						-->
						<view class="content">
							<view class="avatar">
								<image class="image" :src="item.user_info.avatar"></image>
							</view>
							<view class="nickname">
								<text>{{item.user_info.nickname}}</text>
							</view>
							<view class="create-time">
								<text>创建时间：</text><text>{{item.create_time_str}}</text>
							</view>
							<view class="end-time">
								<text>有效期至：</text><text>{{item.end_time_str}}</text>
							</view>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		
		data() {
			return {

				page: 1, //当前页码
				list: [], // 订单列表
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				},
			}
		},
		async onload(option) {
			await this.$onLaunched;
		},
		created() {

		},
		computed: {
			...mapState(['config'])
		},
		methods: {

			//上拉加载的回调
			upCallback: function() {
				let that = this
				let data = {}
					data.page = this.page
					data.action = 'record'
				//获取数据
				let url = '';
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/distribution'
					//#endif
					//#ifdef H5
					url = 'entry/site/distribution'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							let list = res.data.data.data
							that.list = that.list.concat(list);
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(list.length);
							that.page = that.page + 1
						}
					}
				})
			},
			//下拉刷新
			downCallback: function() {
				let that = this
				this.page = 1
				let data = {}
					data.page = this.page
					data.action = 'record'
				//获取数据
				let url = '';
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/distribution'
					//#endif
					//#ifdef H5
					data.action = 'lists'
					url = 'entry/site/distribution'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.list = []
							that.list = res.data.data.data
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(that.list.length);
							that.page = 2
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #f8f8f8;
		min-height: 100%;
		height: auto;
	}
	
	.list {
		
		.item {
			position: relative;
			padding: 20rpx;
			background-color: #fff;
			margin: 20rpx;
			border-radius: 10rpx;
			box-shadow: 0 0 10rpx rgba(0,0,0,.02);
			.title {
				font-size: 32rpx;
				font-weight: 700;
				.status {
					padding: 4rpx 10rpx;
					font-size: 26rpx;
					color: #ffffff;
					border-radius: 8rpx;
				}
				.green {
					background-color: #00ce74;
				}
				.red {
					background-color: #ff0000;
				}
			}
			.delete {
				position: absolute;
				right: 10rpx;
				top: 10rpx;
			}
			.content {
				font-size: 24rpx;
				.avatar {
					position: relative;
					width: 120rpx;
					height: 120rpx;
					margin: 10rpx auto;
					border-radius: 50%;
					overflow: hidden;
					z-index: 2;
					.image {
						width: 120rpx;
						height: 120rpx;
						display: block;
						z-index: 1;
					}
				}
				.nickname {
					color: #000;
					font-size: 26rpx;
					font-weight: 700;
					text-align: center;
					padding-bottom: 20rpx;
				}
				.create-time,.end-time {
					color: #999;
					text-align: center;
				}

			}
			
		}
	}
</style>
